<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_caigoushop/model')->方法名();
*/
namespace jy_caigoushop;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	public function check_credit2($order){
		$merchmid=pdo_getcolumn('jy_merch_user',array('id'=>$order['merchid'],'uniacid'=>$_SESSION['uniacid']),'mid');
		$credit2=pdo_getcolumn('core_members',array('id'=>$merchmid),'credit2');
		if($credit2<$order['price']){
			exi('权限不足，请联系商家！','error');
		}
		return true;
	}
	public function kou_credit2($order){
		$merchmid=pdo_getcolumn('jy_merch_user',array('id'=>$order['merchid'],'uniacid'=>$_SESSION['uniacid']),'mid');
		model('core/member')->member_credit($merchmid,'credit2',$order['price'],true,'jy_caigoushop','客户余额支付下单扣除');
		return true;
	}
	public function checkmerch($merchid=0){
		$merchid=$merchid?:$_SESSION['merchid'];
		if(!$_SESSION['uid']){
			$url='jy_caigoushop/login/';
			exi('请先登录商户！','error',$url);
			return false;
		}
		if($merchid){
			$merch = pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid),array('mid','groupid'));
			if(!$merch['mid'] || $merch['mid'] !=$_SESSION['uid']){
				unset($_SESSION['merchid']);
				$merchid=0;
			}
		}
		if(!$merchid && !$this->setting['isloginmerch']){
			$merch = pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),array('id','mid','groupid'));
			$merchid = $merch['id'];
		}
		if(!$merchid){
			$url='jy_caigoushop/login/';
			exi('请先登录商户！','error',$url);
		}
		if(!$merch['groupid']){
			exi('普通商户不能访问！请联系开通！','error','jy_caigoushop/register/');
		}
		return $merchid;
	}
}
?>